#include <stdio.h>
#include "ukonton.h"
#include "modules.h"

// DLL function signature
typedef ukontonModule* (*importFunction)(void);

modType *modload(char *module)
{
        importFunction getModule;
		modType *mod;

		mod=malloc(sizeof(modType));

        // Load DLL file
        mod->lib = LoadLibraryA(module);
        if (mod->lib == NULL) {
                printf("ERROR: unable to load DLL\n");
                return 0;
        }

        // Get function pointer
        getModule = (importFunction)GetProcAddress(mod->lib, "getModule");
        if (getModule == NULL) {
                printf("ERROR: unable to find DLL function\n");
               FreeLibrary(mod->lib);
                return 0;
        }

        // Call function.
        mod->module = getModule();


        // Unload DLL file
        //FreeLibrary(hinstLib);

        return mod;
}
